package com.cloudsigns.factorymanager2;

import android.app.Activity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.widget.Toast;

import com.cloudsigns.factorymanager2.project.ProjectMainActivity;
import com.cloudsigns.factorymanager2.project.bean.DiskBean;
import com.cloudsigns.factorymanager2.project.customview.DiskView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {

    /**
     * 抽奖的文字
     */
    private String[] mStrs = new String[]{
            "生产", "质检", "工程", "供需", "管理", "项目"};

    private DiskView diskView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        setContentView(R.layout.activity_main);


        init();
    }

    private void init() {
        diskView = (DiskView) findViewById(R.id.diskview);

        DiskBean[] diskBeanArr = new DiskBean[6];
        int checkPosition = 0;

        Intent mIntent = getIntent();
        if (mIntent != null) {
            int flag = mIntent.getExtras().getInt("flag");
            switch (flag) {
                case 1:   //项目
                    for (int i = 0; i < mStrs.length; i++) {
                        if (i == 5) {

                            DiskBean bean = new DiskBean(mStrs[i], BitmapFactory.decodeResource(getResources(), R.mipmap.disk_bg_p), 1);
                            diskBeanArr[i] = bean;
                            checkPosition = i;
                        } else {
                            DiskBean bean = new DiskBean(mStrs[i], BitmapFactory.decodeResource(getResources(), R.mipmap.disk_bg_u), 0);
                            diskBeanArr[i] = bean;
                        }

                    }


                    break;
                case 2:  //工程
                    for (int i = 0; i < mStrs.length; i++) {
                        if (i == 2) {
                            checkPosition = i;
                            DiskBean bean = new DiskBean(mStrs[i], BitmapFactory.decodeResource(getResources(), R.mipmap.disk_bg_p), 1);
                            diskBeanArr[i] = bean;
                        } else {
                            DiskBean bean = new DiskBean(mStrs[i], BitmapFactory.decodeResource(getResources(), R.mipmap.disk_bg_u), 0);
                            diskBeanArr[i] = bean;
                        }

                    }

                    break;
                case 3:  //生产
                    for (int i = 0; i < mStrs.length; i++) {
                        if (i == 0) {
                            checkPosition = i;
                            DiskBean bean = new DiskBean(mStrs[i], BitmapFactory.decodeResource(getResources(), R.mipmap.disk_bg_p), 1);
                            diskBeanArr[i] = bean;
                        } else {
                            DiskBean bean = new DiskBean(mStrs[i], BitmapFactory.decodeResource(getResources(), R.mipmap.disk_bg_u), 0);
                            diskBeanArr[i] = bean;
                        }

                    }
                    break;

            }
        }


        diskView.setDatas(diskBeanArr, checkPosition);

        diskView.setOnWheelCheckListener(new DiskView.OnWheelCheckListener() {
            @Override
            public void onCheck(int position) {
                position = (position + 4) % 6;
                if (position >= 0 && position < mStrs.length)
                    if (position == diskView.getDefaultPosition()) {

                        Intent mIntent = new Intent(MainActivity.this, ProjectMainActivity.class);
                        startActivity(mIntent);
                        finish();
                    } else {
                        Toast.makeText(MainActivity.this, "您没有" + mStrs[position] + "权限", Toast.LENGTH_SHORT).show();
                    }

            }
        });


    }

}
